/**
 * 
 */
package com.nari.heatshare.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.nari.baseinfo.dao.IBuildingDao;
import com.nari.baseinfo.dao.ICommunityDao;
import com.nari.coreframe.service.GenericServiceImpl;
import com.nari.heatshare.dao.ITemperaturePointDataGatherDao;
import com.nari.heatshare.dao.springjdbc.ITempPointDataJdbcDao;
import com.nari.heatshare.model.ITemperaturePointDataGather;
import com.nari.heatshare.utils.queryvo.TempPointDataCustomizedQuery;
import com.nari.platform.model.PageCond;
import com.nari.platform.model.ResponseMsg;
import com.nari.platform.model.ResultWithPageCond;

/**
 * 
 * @author Xiaopeng
 * @date 2014-3-14
 */
public class TemperaturePointDataGatherServiceImpl extends GenericServiceImpl<ITemperaturePointDataGather, String> 
		implements ITemperaturePointDataGatherService {
	private ICommunityDao iCommunityDao;
	private IBuildingDao iBuildingDao;
	private ITempPointDataJdbcDao iTempPointDataJdbcDao;

	/**
	 * 根据温度点编号、所属集中器号、抄表时间查询温度点数据的唯一记录
	 * @param seriousNum
	 * @param concentratorNo
	 * @param recordTime
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-3-17
	 */
	public ITemperaturePointDataGather queryUniqueTempPointData(String seriousNum, String concentratorNo, 
			Date recordTime) throws Exception {
		ITemperaturePointDataGatherDao iTemperaturePointDataGatherDao = (ITemperaturePointDataGatherDao) this.getiGenericDao();
		return iTemperaturePointDataGatherDao.queryUniqueTempPointData(seriousNum, concentratorNo, recordTime);
	}
	
	/**
	 * 新增或修改温度点数据
	 * @param tempPointData
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-3-17
	 */
	public ResponseMsg saveOrUpdateTempPointData(ITemperaturePointDataGather tempPointData) throws Exception {
		ITemperaturePointDataGatherDao iTemperaturePointDataGatherDao = (ITemperaturePointDataGatherDao) this.getiGenericDao();
		return iTemperaturePointDataGatherDao.saveOrUpdateTempPointData(tempPointData);
	}
	
	/**
	 * 根据集中器号、抄表时间查询一个上传批次的温度点数据
	 * @param concentratorNo
	 * @param recordTime
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-3-17
	 */
	public List<ITemperaturePointDataGather> queryUploadBatchTempPointData(String concentratorNo, 
			Date recordTime) throws Exception {
		ITemperaturePointDataGatherDao iTemperaturePointDataGatherDao = (ITemperaturePointDataGatherDao) this.getiGenericDao();
		return iTemperaturePointDataGatherDao.queryUploadBatchTempPointData(concentratorNo, recordTime);
	}
	
	/**
	 * 根据温度点数据列表及集中器号查询其对应的温度点编号-房间号映射表
	 * @param tempPointDataList
	 * @param concentratorNo
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-3-23
	 */
	public Map<String, String> queryReferHouseNoMap(List<ITemperaturePointDataGather> tempPointDataList, 
			String concentratorNo) throws Exception {
		ITemperaturePointDataGatherDao iTemperaturePointDataGatherDao = (ITemperaturePointDataGatherDao) this.getiGenericDao();
		return iTemperaturePointDataGatherDao.queryReferHouseNoMap(tempPointDataList, concentratorNo);
	}
	
	/**
	 * 根据温度点数据列表查询其对应的温度点编号-房间号映射表
	 * @param tempPointDataList
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-4-11
	 */
	public Map<String, String> queryReferHouseNoMap(List<ITemperaturePointDataGather> 
			tempPointDataList) throws Exception {
		ITemperaturePointDataGatherDao iTemperaturePointDataGatherDao = (ITemperaturePointDataGatherDao) this.getiGenericDao();
		return iTemperaturePointDataGatherDao.queryReferHouseNoMap(tempPointDataList);
	}

	/**
	 * 根据任务信息(集中器号、抄表时间)删除温度点数据批次
	 * @param concentratorNo
	 * @param recordTime
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-4-9
	 */
	public void deleteTempPointDataBatch(String concentratorNo, Date recordTime) throws Exception {
		ITemperaturePointDataGatherDao iTemperaturePointDataGatherDao = (ITemperaturePointDataGatherDao) this.getiGenericDao();
		iTemperaturePointDataGatherDao.deleteTempPointDataBatch(concentratorNo, recordTime);
	}
	
	/**
	 * 查询缺少基础档案信息的温度点数据对应的表号
	 * @param concentratorNo
	 * @param recordTime
	 * @param dataType
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-4-9
	 */
	public List<String> queryLackBaseinfoSeriousNum(String concentratorNo, Date recordTime,
			Integer dataType) throws Exception {
		ITemperaturePointDataGatherDao iTemperaturePointDataGatherDao = (ITemperaturePointDataGatherDao) this.getiGenericDao();
		return iTemperaturePointDataGatherDao.queryLackBaseinfoSeriousNum(concentratorNo, recordTime, dataType);
	}
	
	/**
	 * 分页查询温度点数据定制查询列表
	 * @param projectUID
	 * @param communityUID
	 * @param buildingUID
	 * @param recordTimeStart
	 * @param recordTimeEnd
	 * @param pageCond
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2015-1-2
	 */
	public ResultWithPageCond<TempPointDataCustomizedQuery> queryCustomizedQueryPage(String projectUID, 
			String communityUID, String buildingUID, Date recordTimeStart, Date recordTimeEnd,
			PageCond pageCond) throws Exception {
		return iTempPointDataJdbcDao.queryCustomizedQueryPage(projectUID, communityUID, 
				buildingUID, recordTimeStart, recordTimeEnd, pageCond);
	}
	
	/**
	 * 通过定制查询列表查询与之关联的小区映射表
	 * @param customizedList
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-4-11
	 */
	public Map<String, String> queryReferCommunitysByCustomizedList(List<TempPointDataCustomizedQuery> 
			customizedList) throws Exception {
		List<String> communityIDList = null;
		if(customizedList!=null && customizedList.size()>0) {
			communityIDList = new ArrayList<String>();
			for(TempPointDataCustomizedQuery customizedQuery: customizedList) {
				communityIDList.add(customizedQuery.getCommunityUID());
			}
		}
		return iCommunityDao.queryIdNameMapByIDList(communityIDList);
	}
	
	/**
	 * 通过定制查询列表查询与之关联的楼栋映射表
	 * @param customizedList
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-4-11
	 */
	public Map<String, String> queryReferBuildingsByCustomizedList(List<TempPointDataCustomizedQuery> 
			customizedList) throws Exception {
		List<String> buildingIDList = null;
		if(customizedList!=null && customizedList.size()>0) {
			buildingIDList = new ArrayList<String>();
			for(TempPointDataCustomizedQuery customizedQuery: customizedList) {
				buildingIDList.add(customizedQuery.getBuildingUID());
			}
		}
		return iBuildingDao.queryIdNameMapByIDList(buildingIDList);
	}
	
	/**
	 * 根据定制查询特征信息(所属楼栋、抄表时间)统计温度点列表数据个数
	 * @param buildingUID
	 * @param recordTime
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-4-11
	 */
	public int countCustomizedTpDataList(String buildingUID, Date recordTime) throws Exception {
		ITemperaturePointDataGatherDao iTemperaturePointDataGatherDao = (ITemperaturePointDataGatherDao) this.getiGenericDao();
		return iTemperaturePointDataGatherDao.countCustomizedTpDataList(buildingUID, recordTime);
	}
	
	/**
	 * 根据定制查询特征信息(所属楼栋、抄表时间)查询温度点列表数据
	 * @param buildingUID
	 * @param recordTime
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-4-11
	 */
	public List<ITemperaturePointDataGather> queryCustomizedTpDataList(String buildingUID, 
			Date recordTime) throws Exception {
		ITemperaturePointDataGatherDao iTemperaturePointDataGatherDao = (ITemperaturePointDataGatherDao) this.getiGenericDao();
		return iTemperaturePointDataGatherDao.queryCustomizedTpDataList(buildingUID, recordTime);
	}

	/**
	 * @return the iCommunityDao
	 */
	public ICommunityDao getiCommunityDao() {
		return iCommunityDao;
	}

	/**
	 * @param iCommunityDao the iCommunityDao to set
	 */
	public void setiCommunityDao(ICommunityDao iCommunityDao) {
		this.iCommunityDao = iCommunityDao;
	}

	/**
	 * @return the iBuildingDao
	 */
	public IBuildingDao getiBuildingDao() {
		return iBuildingDao;
	}

	/**
	 * @param iBuildingDao the iBuildingDao to set
	 */
	public void setiBuildingDao(IBuildingDao iBuildingDao) {
		this.iBuildingDao = iBuildingDao;
	}

	/**
	 * @return the iTempPointDataJdbcDao
	 */
	public ITempPointDataJdbcDao getiTempPointDataJdbcDao() {
		return iTempPointDataJdbcDao;
	}

	/**
	 * @param iTempPointDataJdbcDao the iTempPointDataJdbcDao to set
	 */
	public void setiTempPointDataJdbcDao(ITempPointDataJdbcDao iTempPointDataJdbcDao) {
		this.iTempPointDataJdbcDao = iTempPointDataJdbcDao;
	}
	
}
